﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Krile.Kernel;
using Krile.Kernel.Data;

namespace Mixture.Common
{
    public static class Receiver
    {
        private static Timer ReceivingTimer;

        public static void Start()
        {
            ReceivingTimer = new Timer(Receive, null, 0, 1000);
        }

        public static void Stop()
        {
            ReceivingTimer = null;
        }

        private static int internalCounter = 0;

        public static void Receive(object o)
        {
            internalCounter++;
            if (internalCounter < Kernel.Config.ReceiveInterval)
            {
                return;
            }
            else
            {
                internalCounter = 0;
            }
            var timelines = IronMixi.MixiApi.GetTimeline(Kernel.Config.account, Mixture.IronMixi.MixiApi.TimelineTypes.Timeline);
            List<Status> news = new List<Status>();
            foreach (var t in timelines)
            {
                if (Kernel.Storage.GetUid(t.Id) == 0)
                {
                    Kernel.Storage.AddSidUid(t.Id, t.UID);
                    news.Add(t);
                }
            }
            Bridge.StatusManager.RegistStatus(news, true);
        }
    }
}
